package sharefolder

import "fmt"

type NfsOpts struct {
	Value  interface{} `json:"value"`
	Output string      `json:"output"`
}

func (opts *NfsOpts) ChangeVal(v string) {
	opts.Value = v
}

func (opts *NfsOpts) Combine(key string) {
	if key != "" {
		opts.Output = fmt.Sprintf("%s=%v", key, opts.Value)
		return
	}
	opts.Output = fmt.Sprintf("%v", opts.Value)
}

func (opts *NfsOpts) ToInt() int {
	if res, ok := opts.Value.(float64); ok {
		return int(res)
	}
	if res, ok := opts.Value.(int); ok {
		return res
	}
	return 0
}

func (opts *NfsOpts) ToString() string {
	if res, ok := opts.Value.(string); ok {
		return res
	}
	return ""
}

func (opts *NfsOpts) Compare(v interface{}) bool {
	switch val := opts.Value.(type) {
	case nil:
		return false
	case string:
		return val == v.(string)
	case int:
		return val == v.(int)
	}
	return false
}
